package com.example.study.config;

import com.rabbitmq.client.ConnectionFactory;
import org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    @Value("${constant.host}")
    private String serviceHost;

    @Bean
    public ConnectionFactory connectionFactory() {
        RabbitConnectionFactoryBean factory = new RabbitConnectionFactoryBean();
        factory.setHost(serviceHost);  // set your host name here
        factory.setPort(5672);  // set your port number here
        factory.setUsername("lufei");  // set your username here
        factory.setPassword("6418019");  // set your password here
        factory.afterPropertiesSet();  // call this method to initialize the factory bean after setting all the properties above
        return factory.getRabbitConnectionFactory();
    }
    // ... other beans ...
}